<?php

namespace App;

class Table
{
	public $cells;
	
	private $baseWidth = 10;
	private $baseHeight = 10;
	private $width;
	private $height;
	
	public function __construct()
	{
		$this->makeTable();
	}
	
	public function makeTable($players = 2)
	{
		$this->cells = array();
		
		$this->width = $this->baseWidth*$players;
		$this->height = $this->baseHeight*$players;
		
		//Make the bidimensional array with random cells
		for($i = 0; $i < $this->width; $i++)
		{
			$this->cells[$i] = array();
			for($j = 0; $j < $this->height; $j++)
				$this->cells[$i][$j] = new Cell(rand(1, 3));
		}
		
		//Make empty initial space
		//Top-left
		$this->cells[0][0]->changeStatus(3);
		$this->cells[0][1]->changeStatus(3);
		$this->cells[1][0]->changeStatus(3);
		
		//Top-right
		$this->cells[0][$this->width-1]->changeStatus(3);
		$this->cells[0][$this->width-2]->changeStatus(3);
		$this->cells[1][$this->width-1]->changeStatus(3);
		
		//bottom-left
		$this->cells[$this->height-2][0]->changeStatus(3);
		$this->cells[$this->height-1][1]->changeStatus(3);
		$this->cells[$this->height-1][0]->changeStatus(3);
		
		//bottom-right
		$this->cells[$this->height-2][$this->width-1]->changeStatus(3);
		$this->cells[$this->height-1][$this->width-2]->changeStatus(3);
		$this->cells[$this->height-1][$this->width-1]->changeStatus(3);
		
		//Las celdas del exterior no son celdas como tal DEPRECATED!
		/*
		//Fill borders with solid indestructible border
		//Top
		for($i = 0; $i < $this->width; $i++)
		{
			$this->cells[0][$i] = new Cell(1);
		}
		//Bottom
		for($i = 0; $i < $this->width; $i++)
		{
			$this->cells[$this->height-1][$i] = new Cell(1);
		}
		
		//Left
		for($i = 0; $i < $this->height; $i++)
		{
			$this->cells[$i][0] = new Cell(1);
		}
		//Right
		for($i = 0; $i < $this->height; $i++)
		{
			$this->cells[$i][$this->width-1] = new Cell(1);
		}
		/* */
	}
}
?>